package top.lyc829.aircontroller.ui.login

import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.text.set
import androidx.lifecycle.ViewModelProvider
import kotlinx.android.synthetic.main.activity_login.*
import top.lyc829.aircontroller.MyApp
import top.lyc829.aircontroller.R


class LoginActivity : AppCompatActivity() {
    lateinit var viewModel: LoginViewModel
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)

        et_username.setText("1823040602")
        et_password.setText("123")

        viewModel = ViewModelProvider(this).get(LoginViewModel::class.java)


        btn_login.setOnClickListener {
            val username = et_username.text.toString()
            val password = et_password.text.toString()
            viewModel.doLogin(username, password)
        }

        viewModel.auth.observe(this) {
            //Toast.makeText(MyApp.context, it, Toast.LENGTH_LONG).show()
            MyApp.sp.putSP("auth", it)
            MyApp.isLogin = true
            finish()
        }

    }
}